package net.dopan.pigframe.demo.service;

import net.dopan.pigframe.core.base.service.BaseService;
import net.dopan.pigframe.demo.model.entity.UserDemo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 * @Package: net.dopan.pigframe.demo.service
 * @Title: UserDemoService
 * @Description: 用户信息
 * @author: 刘宽
 * @date: 2018/10/19 9:47
 */
@CacheConfig(cacheNames = "DEMOUSER")
public interface UserDemoService extends BaseService<UserDemo> {

    /**
     * 添加用户
     * @param user 用户model
     * @return true/false
     */
    @CachePut(key = "'user_' + #user.id")
    Boolean addUser(UserDemo user);

    /**
     * 删除用户
     * @return true/false
     */
    @CacheEvict(key = "#id")
    Boolean deleteById(Long id);

    /**
     * 查询用户
     * @return 用户列表
     */
    @Cacheable(value="USER#100", key = "#id")
    UserDemo findById(Long id);

    /**
     * 更新用户
     * @return true/false
     */
    @CacheEvict(key = "#user.id")
    Boolean myUpdateById(UserDemo user);

    /**
     * 获取用户
     * @return 所有用户列表
     */
    @Cacheable(key = "'user_all_list'")
    List<UserDemo> getUser();

}
